package com.study.a01mystream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Function;
import java.util.stream.Stream;

public class StreamDemo7 {
    public static void main(String[] args) {

        ArrayList<String> list=new ArrayList<>();
        Collections.addAll(list,"张三-12","李四-13","王五-14","王六-15","王七-16","张无极-17");

        ArrayList<String> list2=new ArrayList<>();
        Collections.addAll(list2,"周芷若","赵敏");

        //元素去重
        list.stream().distinct().forEach(name-> System.out.println(name));

        //合并
        Stream.concat(list.stream(),list2.stream()).forEach(name-> System.out.println(name));
        
        //只获取int类型的元素
        //第一个类型，流原本的数据类型
        //第二个类型，转之后的类型
        list.stream().map(new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                String[] split = s.split("-");
                String ageString = split[1];
                int age = Integer.parseInt(ageString);

                return age;
            }
        }).forEach(age-> System.out.println(age));


        //化简
        list.stream()
                .map(s->Integer.parseInt(s.split("-")[1]))
                .forEach(s-> System.out.println(s));



    }
}
